/**
 * Created by PanJiaChen on 16/11/18.
 */

/**
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal(path) {
  return /^(https?:|mailto:|tel:)/.test(path)
}

/**
 * @param {string} str
 * @returns {Boolean}
 */
export function validUsername(str) {
  const valid_map = ['admin', 'editor', 'user']
  return valid_map.indexOf(str.trim()) >= 0
}

export function validNotNull(str) {
  return str.trim().length > 0
}

/**
 * @param {string} url
 * @returns {Boolean}
 */
export function validURL(url) {
  const reg = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
  return reg.test(url)
}

/**
 * @param {string} str
 * @returns {Boolean}
 */
export function validLowerCase(str) {
  const reg = /^[a-z]+$/
  return reg.test(str)
}

/**
 * @param {string} str
 * @returns {Boolean}
 */
export function validUpperCase(str) {
  const reg = /^[A-Z]+$/
  return reg.test(str)
}

/**
 * @param {string} str
 * @returns {Boolean}
 */
export function validAlphabets(str) {
  const reg = /^[A-Za-z]+$/
  return reg.test(str)
}

/**
 * @param {string} email
 * @returns {Boolean}
 */
export function validEmail(email) {
  const reg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
  return reg.test(email)
}

/**
 * @param {string} str
 * @returns {Boolean}
 */
export function isString(str) {
  if (typeof str === 'string' || str instanceof String) {
    return true
  }
  return false
}

/**
 * @param {Array} arg
 * @returns {Boolean}
 */
export function isArray(arg) {
  if (typeof Array.isArray === 'undefined') {
    return Object.prototype.toString.call(arg) === '[object Array]'
  }
  return Array.isArray(arg)
}

// 2.password 长度6-16
export function validPassword(str) {
  return str.length >= 6 && str.length <= 16
}

// 3.email address
export function validEmailAddress(str) {
  const reg = new RegExp(/\w{4,20}@(163|126|qq).com$/)
  console.log(reg.exec(str))
  return reg.exec(str) != null
}

// 4.head picture file
export function validHeadPic(str) {

}

// 5.time day
export function validDateDay(str) {
  const reg = new RegExp(/^\d{4}-\d{1,2}-\d{1,2}/)
  return reg.exec(str) != null
}

// 6.bank count
export function validBankCount(str) {
  const reg = new RegExp(/^[1-9]\d{9,29}$/)
  return reg.exec(str) != null
}

// 7.validChinese
export function validChinese(str) {
  const reg = new RegExp(/^[\u4e00-\u9fa5]*$/)
  return reg.exec(str) != null
}

// 8.邮政编码
export function validPostalCode(str) {
  const reg = new RegExp(/[1-9]\d{5}(?!\d)/)
  return reg.exec(str) != null
}

// 9.float number
export function validFloatNumber(str) {
  const reg = new RegExp(/^-[1-9]\d*\.\d*|-0\.\d*[1-9]\d*$/)
  return reg.exec(str) != null
}

// 10.integer number
export function validIntegerNumber(str) {
  const reg = new RegExp(/^\d*$/)
  return reg.exec(str) != null
}

// 11.char with number
export function validCharAndNumber(str) {
  const reg = new RegExp(/^[A-Za-z\d]+$/)
  return reg.exec(str) != null
}

// 13.Phone number
export function validPhoneNumber(str) {
  const reg = new RegExp(/^(13[0-9]|17[0-9]|14[5|7]|15[0-9]|18[0-9]|19[4|5])\d{8}$/)
  return reg.exec(str) != null
}

// 14.QQ
export function validQQ(str) {
  const reg = new RegExp(/[1-9]\d{4,}/)
  return reg.exec(str) != null
}

// 15.图片文件 ^([a-zA-Z])+.(gif|png|jpg|jpeg|webp|svg|psd|bmp|tif)$
export function validFileOfPicture(str) {
  const reg = new RegExp(/^([a-zA-Z])+.(gif|png|jpg|jpeg|webp|svg|psd|bmp|tif)$/)
  return reg.exec(str) != null
}
// 16.火车车次 ^[GCDZTSPKXLY1-9]\d{1,4}$
export function validLocomotiveNo(str) {
  const reg = new RegExp(/^[GCDZTSPKXLY1-9]\d{1,4}$/)
  return reg.exec(str) != null
}

// 17.中文、英文、数字包括下划线：^[\u4E00-\u9FA5A-Za-z0-9_]+$
export function validLegalPassword(str) {
  const reg = new RegExp(/^[\u4E00-\u9FA5A-Za-z0-9_]+$/)
  return reg.exec(str) != null
}

// 18.视频文件 ^([a-zA-Z])+.(swf|avi|flv|mpg|rm|mov|wav|asf|3gp|mkv|rmvb|mp4)$
export function validFileOfVideo(str) {
  const reg = new RegExp(/^([a-zA-Z])+.(swf|avi|flv|mpg|rm|mov|wav|asf|3gp|mkv|rmvb|mp4)$/)
  return reg.exec(str) != null
}

// 19.车牌 ^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]$
export function validCarNo(str) {
  const reg = new RegExp(/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]$/)
  return reg.exec(str) != null
}

// 20.护照 (^[EeKkGgDdSsPpHh]\d{8}$)|(^(([Ee][a-fA-F])|([DdSsPp][Ee])|([Kk][Jj])|([Mm][Aa])|(1[45]))\d{7}$)
export function validVisa(str) {
  const reg = new RegExp(/(^[EeKkGgDdSsPpHh]\d{8}$)|(^(([Ee][a-fA-F])|([DdSsPp][Ee])|([Kk][Jj])|([Mm][Aa])|(1[45]))\d{7}$)/)
  return reg.exec(str) != null
}

// 21.澳门身份证 ^[1|5|7]\d{6}[(\d)]{3}$
export function validA0MenID(str) {
  const reg = new RegExp(/^[1|5|7]\d{6}[(\d)]{3}$/)
  return reg.exec(str) != null
}

export function validIdNumber(str) {
  const reg = new RegExp(/^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[1-2]\d|30|31)\d{3}[\dXx]$/)
  return reg.exec(str) != null
}

// 22.分数 ^150$|^(?:\d|[1-9]\d|1[0-4]\d)(?:\.5)?$

// 23.A股 ^(s[hz]|S[HZ])(000[\d]{3}|002[\d]{3}|300[\d]{3}|600[\d]{3}|60[\d]{4})$

// 24.座机号码 ^\d{3}-\d{8}|\d{4}-\d{7,8}

// 25.word文件 ^([a-zA-Z])+.(doc|docx)$

// 26.pdf ^([a-zA-Z])+.(pdf)$

// 27.压缩文件 ^([a-zA-Z])+.(zip|rar|7z)$
